import request from "@/utils/request";

// 查询流程定义列表
export function getProcessDefinition(query) {
  return request({
    url: '/api/camunda/getProcessDefinition',
    method: 'get',
    params: query
  })
}

// 根据部署ID删除流程定义
export function removeProcessDefinitionByDeploymentId(deploymentId) {
  return request({
    url: '/api/camunda/removeProcessDefinitionByDeploymentId/' + deploymentId,
    method: 'get'
  })
}

// 获取BPMN模型
export function getProcessBpmn(deploymentId) {
  return request({
    url: '/api/camunda/getProcessBpmn/' + deploymentId,
    method: 'get'
  })
}

// 修改流程定义的状态
export function updateProcessStatus(key) {
  return request({
    url: '/api/camunda/updateProcessStatus/' + key,
    method: 'put'
  })
}

// 发布工作流程
export function createProcessDefinition(id) {
  return request({
    // headers: { 'content-type' : 'multipart/form-data' },
    url: `/api/camunda/createProcessDefinition/` + id,
    method: 'get'
  })
}


// 获取流程定义监控
export function getProcessControl(page) {
  return request({
    url: '/api/camunda/getProcessControl',
    method: 'post',
    data: page
  })
}

// 删除流程定义监控
export function deleteProcessControl(processInstanceIds) {
  return request({
    url: '/api/camunda/deleteProcessControl/' + processInstanceIds,
    method: 'delete'
  })
}

// 获取流程的表单
export function getProcessForm(processInstanceId) {
  return request({
    url: '/api/camunda/getProcessForm/' + processInstanceId,
    method: 'get'
  })
}

// 获取流程的审批意见
export function getProcessComment(processInstanceId) {
  return request({
    url: '/api/camunda/getProcessComment/' + processInstanceId,
    method: 'get'
  })
}

// 获取需要展示的流程图
export function getProcessShowBpmn(processInstanceId) {
  return request({
    url: '/api/camunda/getProcessShowBpmn/' + processInstanceId,
    method: 'get'
  })
}

// 获取当前部署流程的节点的权限
export function getProcessAuth(taskId) {
  return request({
    url: '/api/camunda/getProcessAuth/' + taskId,
    method: 'get'
  })
}

// 完成任务
export function completeTask(map, taskId, opinion, option) {
  return request({
    url: `/api/camunda/completeTask`,
    method: 'post',
    data: { map: map, taskId: taskId, opinion: opinion, option: option }
  })
}

// 加签
export function addSign(taskId, userId, opinion) {
  return request({
    url: `/api/camunda/addSign`,
    method: 'post',
    data: { taskId: taskId, userId: userId, opinion: opinion }
  })
}

// 获取选人列表
export function selectAddSignUser(taskId) {
  return request({
    url: '/api/camunda/selectAddSignUser/' + taskId,
    method: 'get'
  })
}

// 获取办理的选人列表
export function selectCompleteUser(taskId) {
  return request({
    url: '/api/camunda/selectCompleteUser/' + taskId,
    method: 'get'
  })
}

// 获取减签的选人列表
export function selectDeleteSignUser(taskId) {
  return request({
    url: '/api/camunda/selectDeleteSignUser/' + taskId,
    method: 'get'
  })
}

// 减签
export function deleteSign(taskId, userId, opinion) {
  return request({
    url: `/api/camunda/deleteSign`,
    method: 'post',
    data: { taskId: taskId, userId: userId, opinion: opinion }
  })
}

// 委托
export function delegate(taskId, userId, opinion) {
  return request({
    url: `/api/camunda/delegate`,
    method: 'post',
    data: { taskId: taskId, userId: userId, opinion: opinion }
  })
}

// 完成委托
export function completeDelegate(taskId, map, opinion) {
  return request({
    url: `/api/camunda/completeDelegate`,
    method: 'post',
    data: { taskId: taskId, map: map, opinion: opinion }
  })
}

// 取消委托
export function cancelDelegate(taskId, opinion) {
  return request({
    url: `/api/camunda/cancelDelegate`,
    method: 'post',
    data: { taskId: taskId, opinion: opinion }
  })
}

// 转办
export function relayComplete(taskId, userId, opinion) {
  return request({
    url: `/api/camunda/relayComplete`,
    method: 'post',
    data: { taskId: taskId, userId: userId, opinion: opinion }
  })
}

// 退回到上一步的任务
export function returnBackTask(taskId, opinion) {
  return request({
    url: `/api/camunda/returnBackTask`,
    method: 'post',
    data: { taskId: taskId, opinion: opinion }
  })
}

// 设计模板页面，获取选人列表
export function getChoseUser(chose) {
  return request({
    url: `/api/camunda/getChoseUser`,
    method: 'post',
    data: {chose: chose}
  })
}

// 设计模板页面，获取选人列表
export function getChoseAuth(chose) {
  return request({
    url: `/api/camunda/getChoseAuth`,
    method: 'post',
    data: {chose: chose}
  })
}

// 设计模板页面，获取表达式列表
export function getChoseCondition() {
  return request({
    url: `/api/camunda/getChoseCondition`,
    method: 'post'
  })
}

// 设计模板页面，根据表单标识获取表单中的变量
export function getFormVariable(formIdList) {
  return request({
    url: `/api/camunda/getFormVariable`,
    method: 'post',
    data: formIdList
  })
}

// 根据当前用户获取流程实例列表
export function getProcessInstanceByUser(query) {
  return request({
    url: '/api/camunda/getProcessInstanceByUser',
    method: 'post',
    data: query
  })
}

// 根据当前用户获取用户任务列表
export function getUserTaskByUser(query) {
  return request({
    url: '/api/camunda/getUserTaskByUser',
    method: 'post',
    data: query
  })
}

// 根据当前用户获取发出委托的用户任务列表
export function getDelegateTaskByUser(query) {
  return request({
    url: '/api/camunda/getDelegateTaskByUser',
    method: 'post',
    data: query
  })
}

// 根据当前用户获取具有的流程
export function getProcessByUserId() {
  return request({
    url: '/api/camunda/getProcessByUserId',
    method: 'get'
  })
}

// 获取流程的开始表单
export function getProcessStartForm(query) {
  return request({
    url: '/api/camunda/getProcessStartForm',
    method: 'post',
    data: query
  })
}

// 根据流程Key和版本号开启流程
export function startProcessByVersion(processKey, version, businessKey, map) {
  return request({
    url: '/api/camunda/startProcessByVersion',
    method: 'post',
    data: { processKey, version, businessKey, map }
  })
}

// 获取流程的第一个节点的选人列表
export function getStartProcessUserList(processKey, version) {
  return request({
    url: '/api/camunda/getStartProcessUserList',
    method: 'post',
    data: { processKey, version }
  })
}

// 根据流程Key和版本号获取流程模型
export function getProcessBpmnByVersion(processKey, version) {
  return request({
    url: '/api/camunda/getProcessBpmnByVersion',
    method: 'post',
    data: { processKey, version }
  })
}

// 获取流程定义的变量
export function getProcessVariable(processInstanceId) {
  return request({
    url: '/api/camunda/getProcessVariable/' + processInstanceId,
    method: 'get'
  })
}

// 获取流程审批日志流程
export function getProcessCommentLog(processInstanceId) {
  return request({
    url: '/api/camunda/getProcessCommentLog/' + processInstanceId,
    method: 'get'
  })
}

// 获取流程审批日志流程
export function getProcessNodeLog(processInstanceId) {
  return request({
    url: '/api/camunda/getProcessNodeLog/' + processInstanceId,
    method: 'get'
  })
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

export function initDeployedStartForm() {
    return request({
        url: `/api/camunda/initDeployedStartForm`,
        method: 'get'
    })
}
